class ERobot {
  constructor(conf) {
    this.wzq = {
      getChessBoard(){},
      getWins() {},
      getCount() {},
      getOneWins() {},
      BLACK_COLOR: null,
      NULL_CHESS: null,
      WHITE_COLOR: null
    };
    this.conf = conf;
    this.myColor = null;
  }
  
  connect(wzq) {
    this.wzq = wzq;
    return this;
  }

  hold(color) {
    this.myColor = color;
    return this;
  }

  drop(done) {
    this._drop(this.myColor, done);
  }

  _drop(type, done) {
    var chessBoard = this.wzq.getChessBoard();
    var wins = this.wzq.getWins();
    var count = this.wzq.getCount();
    var myWin = this.wzq.getOneWins(type);
    var otherType = type === this.wzq.BLACK_COLOR ? this.wzq.BLACK_COLOR : this.wzq.BLACK_COLOR;
    var computerWin = this.wzq.getOneWins(otherType);

    var myScore = [];
    var computerScore = [];
    var max = 0;
    var u = 10, v = 10;
    var hasPos = false;
    for (var i = 0; i < 19; i++) {
      myScore[i] = [];
      computerScore[i] = [];
      for (var j = 0; j < 19; j++) {
        myScore[i][j] = 0;
        computerScore[i][j] = 0;
      }
    }
    for (var i = 0; i < 19; i++) {
      for (var j = 0; j < 19; j++) {
        if (chessBoard[i][j] === this.wzq.NULL_CHESS) {
          hasPos = true;
          for (var k = 0; k < count; k++) {
            if (wins[i][j][k]) {
              if (myWin[k] == 1) {
                myScore[i][j] += this.conf.m[1] * (1 + Math.random() / 2);
              } else if (myWin[k] == 2) {
                myScore[i][j] += this.conf.m[2] * (1 + Math.random() / 2);
              } else if (myWin[k] == 3) {
                myScore[i][j] += this.conf.m[3] * (1 + Math.random() / 2);
              } else if (myWin[k] == 4) {
                myScore[i][j] += this.conf.m[4] * (1 + Math.random() / 2);
              }
              if (computerWin[k] == 1) {
                computerScore[i][j] += this.conf.c[1] * (1 + Math.random() / 2);
              } else if (computerWin[k] == 2) {
                computerScore[i][j] += this.conf.c[2] * (1 + Math.random() / 2);
              } else if (computerWin[k] == 3) {
                computerScore[i][j] += this.conf.c[3] * (1 + Math.random() / 2);
              } else if (computerWin[k] == 4) {
                computerScore[i][j] += this.conf.c[4] * (1 + Math.random() / 2);
              }
            }
          }
          if (myScore[i][j] > max) {
            max = myScore[i][j];
            u = i;
            v = j;
          } else if (myScore[i][j] == max) {
            if (computerScore[i][j] > computerScore[u][v]) {
              u = i;
              v = j;
            }
          }
          if (computerScore[i][j] > max) {
            max = computerScore[i][j];
            u = i;
            v = j;
          } else if (computerScore[i][j] == max) {
            if (myScore[i][j] > myScore[u][v]) {
              u = i;
              v = j;
            }
          }
        }
      }
    }
    if (hasPos) {
      done(u, v, type);
    }
  }
}
console.log(111);